package com.ziyun.erp.web.modules.capital.controller;

import java.util.Arrays;
import java.util.Map;

import com.ziyun.erp.common.utils.UserUtils;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.capital.entity.SupplierApplyCashRuleEntity;
import com.ziyun.erp.modules.capital.service.SupplierApplyCashRuleService;
import io.renren.common.utils.R;



/**
 * 工厂提现规则
 *
 * @author gaosheng
 * @email 
 * @date 2018-11-08 14:54:49
 */
@RestController
@RequestMapping("capital/supplierapplycashrule")
public class SupplierApplyCashRuleController {
    @Autowired
    private SupplierApplyCashRuleService supplierApplyCashRuleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("capital:supplierapplycashrule:list")
    public R list(@RequestParam Map<String, Object> params){
        return supplierApplyCashRuleService.queryPageApplyCashRuleList(params);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{ruleId}")
    public R info(@PathVariable("ruleId") Integer ruleId){
        SupplierApplyCashRuleEntity supplierApplyCashRule = supplierApplyCashRuleService.selectById(ruleId);

        return R.ok().put("supplierApplyCashRule", supplierApplyCashRule);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("capital:supplierapplycashrule:save")
    public R save(@RequestBody SupplierApplyCashRuleEntity supplierApplyCashRule){
        supplierApplyCashRuleService.insert(supplierApplyCashRule);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("capital:supplierapplycashrule:update")
    public R update(@RequestBody SupplierApplyCashRuleEntity supplierApplyCashRule){
        ValidatorUtils.validateEntity(supplierApplyCashRule);
        Long userId = UserUtils.getCurentUser().getUserId();
        return supplierApplyCashRuleService.updateSupplierApplyCashRule(supplierApplyCashRule, userId);
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ruleIds){
        return supplierApplyCashRuleService.deleteApplyCashRule(Arrays.asList(ruleIds));
    }

}
